﻿using EasyTest.Shared.EnumType;
using EasyTest.Shared.TestAttribute;
using EasyTest.Shared.外部访问;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;


namespace ZLGCANoptimize
{
    public class 蓝牙
    {
       

        [ExposedMethodAttribute("")]
        public bool 切换蓝牙音源(int 通道, out string 信息, out string data,string 解密="01")
        {
#if ELO20240927
            data = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道,new List<ZCAN_Receive_Data>(), out 信息, 解密);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1;
                result1 = zLGCANHelper.SentData(通道, 0x761, "04 2E 4C 10 05 00 00 00", true, SendType.正常发送);
                if (!result1)
                {
                    信息 = "发送数据失败,切换蓝牙音源失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E 4C 10"))
                        {
                            信息 = "切换蓝牙音源成功";
                            return true;
                        }
                    }
                }

                信息 = "切换蓝牙音源失败";
            }
            catch (Exception ex)
            {
                信息 = "切换蓝牙音源失败" + ex.Message;
            }
            return false;
#else
            data = "";

            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1, result2;
                result1 = zLGCANHelper.SentData(通道, 0x761, "10 0C 2E 4C 10 05 00 00", true, SendType.正常发送);
                Thread.Sleep(50);
                result2 = zLGCANHelper.SentData(通道, 0x761, "21 00 00 00 00 00 00 00", true, SendType.正常发送);
                if (!result1)
                {
                    信息 = "发送数据失败,切换蓝牙音源失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);//03 6E 4C 83 AA AA AA AA 
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        //03 6E 4C 10 AA AA AA AA
                        if (s.Trim().StartsWith("03 6E 4C 10"))
                        {
                            信息 = "切换蓝牙音源成功";
                            return true;
                        }
                    }

                }

                //3、关闭
                信息 = "切换蓝牙音源失败";
                return false;
            }
            catch (Exception ex)
            {
                信息 = "切换蓝牙音源失败" + ex.Message;
                return false;
            }
#endif
        }

     //   [ExposedMethodAttribute("")]
        public bool 删除蓝牙配对(int 通道, out string 信息, out string data, string 解密 = "01")
        {
#if ELO20240927
            data = "";

            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道,new List<ZCAN_Receive_Data>(), out 信息, 解密);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1;
                result1 = zLGCANHelper.SentData(通道, 0x761, "04 2E 4C 86 01 00 00 00", true, SendType.正常发送);

                if (!result1)
                {
                    信息 = "发送数据失败,删除蓝牙配对失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E 4C 86"))
                        {
                            信息 = "删除蓝牙配对成功";
                            return true;
                        }
                    }

                }

                信息 = "删除蓝牙配对失败";
            }
            catch (Exception ex)
            {
                信息 = "删除蓝牙配对失败" + ex.Message;
            }
            return false;
#else
            data = "";

            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1, result2;
                result1 = zLGCANHelper.SentData(通道, 0x761, "07 2E 4C 86 01 00 00 00", true, SendType.正常发送);

                if (!result1)
                {
                    信息 = "发送数据失败,删除蓝牙配对失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);//03 6E 4C 83 AA AA AA AA 
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        //03 6E 4C 86 AA AA AA AA
                        if (s.Trim().StartsWith("03 6E 4C 86"))
                        {
                            信息 = "删除蓝牙配对成功";
                            return true;
                        }
                    }

                }

                //3、关闭
                信息 = "删除蓝牙配对失败";
                return false;
            }
            catch (Exception ex)
            {
                信息 = "删除蓝牙配对失败" + ex.Message;
                return false;
            }
#endif
        }

       // [ExposedMethodAttribute("")]
//        public bool MAC地址(int 通道, out string mac地址, out string 信息, out string data)
//        {
//#if ELO20240927
//            data = "";
//            mac地址 = "";
//            try
//            {
//                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
//                {
//                    信息 = "启动can设备失败";
//                    return false;
//                }
//                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
//                //bool OK = Can.解密(通道, out 信息, "01");
//                //if (!OK)
//                //{
//                //    信息 = "解密失败";
//                //    mac地址 = 信息;
//                //    return false;
//                //}
//                bool result1 = false;

//                result1 = zLGCANHelper.SentData(通道, 0x761, "03 22 4C 8B 00 00 00 00", true, SendType.正常发送);
//                Thread.Sleep(50);
//                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
//                Thread.Sleep(100);
//                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
//                Thread.Sleep(50);

//                if (!result1)
//                {
//                    信息 = "发送数据失败,读取蓝牙 Mac地址失败";
//                    mac地址 = 信息;
//                    return false;
//                }
//                Thread.Sleep(500);
//                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
//                //10 0A 62 4C 8B 00 48 42              
//                // 21 21 77 24 80 AA AA AA
//                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);// 03 6E 4C 10 AA AA AA AA
//                data = string.Join("\n", datas);
//                string[] hexValues = new string[6];
//                bool ok10 = false;
//                bool ok21 = false;
//                int num = 0;
//                foreach (string s in datas)
//                {
//                    if (s.Trim().StartsWith("10"))
//                    {
//                        ok10 = true;
//                        for (int i = 0; i < s.Split(' ').Length; i++)
//                        {
//                            if (i < 5 || i > 7) continue;
//                            hexValues[num] = s.Split(' ')[i];
//                            num++;
//                        }
//                    }
//                    else if (s.Trim().StartsWith("21"))
//                    {
//                        ok21 = true;
//                        for (int i = 0; i < s.Split(' ').Length; i++)
//                        {
//                            if (i < 1 || i > 3) continue;
//                            hexValues[num] = s.Split(' ')[i];
//                            num++;
//                        }
//                    }
//                }
//                mac地址 = string.Join("", hexValues);
//                信息 = string.Join(",", hexValues);
//                if (ok10 && ok21 && mac地址.Length == 12)
//                {
//                    return true;
//                }
//                else if (mac地址.Length != 12)
//                {
//                    信息 = "长度NG";
//                    mac地址 = data;
//                }
//                else
//                {
//                    return false;
//                }
//                return false;
//            }
//            catch (Exception ex)
//            {
//                信息 = "读取蓝牙地址失败" + ex.Message;
//                mac地址 = 信息;
//                return false;
//            }
//#else
//            data = "";
//            mac地址 = "";
//            try
//            {
//                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
//                {
//                    信息 = "启动can设备失败";
//                    return false;
//                }
//                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
//                //bool OK = Can.解密(通道, out 信息, "01");
//                //if (!OK)
//                //{
//                //    信息 = "解密失败";
//                //    mac地址 = 信息;
//                //    return false;
//                //}
//                bool result1 = false, result2 = false;

//                result1 = zLGCANHelper.SentData(通道, 0x761, "03 22 4C 8B 00 00 00 00", true, SendType.正常发送);
//                Thread.Sleep(50);
//                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
//                Thread.Sleep(100);
//                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);

//                if (!result1)
//                {
//                    信息 = "发送数据失败,读取蓝牙 Mac地址失败";
//                    mac地址 = 信息;
//                    return false;
//                }
//                Thread.Sleep(500);
//                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
//                //10 0A 62 4C 8B 00 48 42              
//                // 21 21 77 24 80 AA AA AA
//                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);// 03 6E 4C 10 AA AA AA AA
//                data = string.Join("\n", datas);
//                string[] hexValues = new string[6];
//                bool ok10 = false;
//                bool ok21 = false;
//                bool ok22 = false;
//                int num = 0;
//                foreach (string s in datas)
//                {
//                    if (s.Trim().StartsWith("10"))
//                    {
//                        ok10 = s.Split(' ')[5] == "00";
//                        for (int i = 0; i < s.Split(' ').Length; i++)
//                        {
//                            if (i <= 5 || i > 7) continue;
//                            hexValues[num] = s.Split(' ')[i];
//                            num++;
//                        }
//                    }
//                    else if (s.Trim().StartsWith("21"))
//                    {
//                        ok21 = true;
//                        for (int i = 0; i < s.Split(' ').Length; i++)
//                        {
//                            if (i == 0 || i > 4) continue;
//                            hexValues[num] = s.Split(' ')[i];
//                            num++;
//                        }
//                    }
//                }
//                mac地址 = string.Join("", hexValues);
//                信息 = string.Join(",", hexValues);
//                if (ok10 && ok21 && mac地址.Length == 12)
//                {
//                    return true;
//                }
//                else if (mac地址.Length != 12)
//                {
//                    信息 = "长度NG";
//                    mac地址 = data;
//                }
//                else
//                {
//                    return false;
//                }
//                return false;
//            }
//            catch (Exception ex)
//            {
//                信息 = "读取蓝牙地址失败" + ex.Message;
//                mac地址 = 信息;
//                return false;
//            }
//#endif
//        }

        [ExposedMethodAttribute("")]
        public bool 设置自动配对4C84(int 通道, out string 信息, out string data, int 开关 = 1)
        {
#if ELO20240927
            data = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道,new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1;
                string str = "04 2E 4C 84 02 00 00 00";
                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"设置自动配对4C84命令：{str}", eMsgType.Debug);
                if (!result1)
                {
                    信息 = "发送数据失败,设置自动配对4C84失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);//03 6E 4C 83 AA AA AA AA 
                eLog.AddLog($"设置自动配对4C84响应：{string.Join(",", datas)}", eMsgType.Debug);
                data = string.Join(",", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        //03 6E 4C 86 AA AA AA AA
                        if (s.Trim().StartsWith("03 6E 4C 84"))
                        {
                            信息 = "设置自动配对4C84成功";
                            return true;
                        }
                    }
                }
                信息 = "设置自动配对4C84失败";
            }
            catch (Exception ex)
            {
                信息 = "设置自动配对4C84失败" + ex.Message;
            }
            return false;
#else
            data = "";
            string 首帧 = "";
            if (开关 != 1)
            {
                首帧 = "07 2E 4C 84 02 00 00 00";
                首帧 = "10 0C 2E 4C 10 05 00 00";
            }
            else
            {
                首帧 = "07 2E 4C 84 01 00 00 00";
            }
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1, result2;
                result1 = zLGCANHelper.SentData(通道, 0x761, "07 2E 4C 84 02 00 00 00", true, SendType.正常发送);
                //Thread.Sleep(50);
                //result2 = zLGCANHelper.SentData(通道, 0x761, "21 02 00 00 00 00 AA AA", true, SendType.正常发送);
                if (!result1)
                {
                    信息 = "发送数据失败,关闭确认失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);//03 6E 4C 83 AA AA AA AA 
                data = string.Join(",", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        //03 6E 4C 86 AA AA AA AA
                        if (s.Trim().StartsWith("03 6E 4C 84"))
                        {
                            信息 = "关闭确认成功";
                            return true;
                        }
                    }
                }
                信息 = "关闭确认失败";
                return false;
            }
            catch (Exception ex)
            {
                信息 = "关闭确认失败" + ex.Message;
                return false;
            }
#endif
        }


        //=================================== 2024-09-27 ELO指令更新，以下方法为对应更新的内容 ==========================================
        [ExposedMethodAttribute("")]
        public bool 切换蓝牙音源4C10(int 通道, out string 信息, out string data)
        {
            data = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1;
                string str = "10 0C 2E 4C 10 05 00 00";//04 2E 4C 10 05 00 00 00
                string str2 = "21 00 00 00 00 00 00 00";
                //10 0C 2E 4C 10 05 00 00
                //21 00 00 00 00 00 00 00
                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"切换蓝牙音源4C10命令：{str}", eMsgType.Debug);
                Thread.Sleep(50);
                result1 = zLGCANHelper.SentData(通道, 0x761, str2, true, SendType.正常发送);
                eLog.AddLog($"切换蓝牙音源4C10命令：{str2}", eMsgType.Debug);
                if (!result1)
                {
                    信息 = "发送数据失败,切换蓝牙音源失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"切换蓝牙音源4C10响应：{string.Join(",", datas)}", eMsgType.Debug);
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E 4C 10"))
                        {
                            信息 = "切换蓝牙音源成功";
                            return true;
                        }
                    }
                }

                信息 = "切换蓝牙音源失败";
            }
            catch (Exception ex)
            {
                信息 = "切换蓝牙音源失败" + ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 停止播放蓝牙音源4C87(int 通道, out string 信息, out string data)
        {
            data = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1;
                string str = "10 0C 2E 4C 87 01 00 00";
                string str2 = "21 00 00 00 00 00 00 00";
                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"停止播放蓝牙音源4C87命令：{str}", eMsgType.Debug);
                Thread.Sleep(50);
                result1 = zLGCANHelper.SentData(通道, 0x761, str2, true, SendType.正常发送);
                eLog.AddLog($"停止播放蓝牙音源4C87命令：{str2}", eMsgType.Debug);
                if (!result1)
                {
                    信息 = "发送数据失败,切换蓝牙音源失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"停止播放蓝牙音源4C87响应：{string.Join(",", datas)}", eMsgType.Debug);
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E 4C 87"))
                        {
                            信息 = "切换蓝牙音源成功";
                            return true;
                        }
                    }
                }

                信息 = "切换蓝牙音源失败";
            }
            catch (Exception ex)
            {
                信息 = "切换蓝牙音源失败" + ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 删除蓝牙配对4C86(int 通道, out string 信息, out string data)
        {
            data = "";

            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1;//07 2E 4C 86 01 00 00 00
                string str = "07 2E 4C 86 01 00 00 00";
                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"删除蓝牙配对4C86命令：{str}", eMsgType.Debug);
                if (!result1)
                {
                    信息 = "发送数据失败,删除蓝牙配对失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"删除蓝牙配对4C86响应：{string.Join(",", datas)}", eMsgType.Debug);
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E 4C 86"))
                        {
                            信息 = "删除蓝牙配对成功";
                            return true;
                        }
                    }

                }

                信息 = "删除蓝牙配对失败";
            }
            catch (Exception ex)
            {
                信息 = "删除蓝牙配对失败" + ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 清空蓝牙列表4C86(int 通道, out string 信息, out string data)
        {
            data = "";

            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1;//07 2E 4C 86 01 00 00 00
                string str = "07 2E 4C 86 01 00 00 00";
                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"清空蓝牙列表4C86mingl：{str}", eMsgType.Debug);
                if (!result1)
                {
                    信息 = "发送数据失败,清空蓝牙列表失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"清空蓝牙列表4C86响应：{string.Join(",", datas)}", eMsgType.Debug);
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E 4C 86"))
                        {
                            信息 = "清空蓝牙列表成功";
                            return true;
                        }
                    }

                }

                信息 = "清空蓝牙列表失败";
            }
            catch (Exception ex)
            {
                信息 = "清空蓝牙列表失败" + ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 打开蓝牙4C83(int 通道, out string 信息, out string data)
        {
            data = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息,"61");
                if (!OK)
                {
                    return false;
                }
                bool result1 = false;//05 2E 4C 83 01 00 00 00
                for (int i = 0; i < 3; i++)
                {
                    result1 = zLGCANHelper.SentData(通道, 0x761, "05 2E 4C 83 01 00 00 00", true, SendType.正常发送);
                    if (result1)
                    {
                        break;
                    }
                }
                if (!result1)
                {
                    信息 = "发送数据失败,打开蓝牙失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);//03 6E 4C 83 AA AA AA AA 
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {

                        if (s.Trim().StartsWith("03 6E 4C 83"))
                        {
                            信息 = "打开蓝牙成功";
                            return true;
                        }
                    }
                }

                信息 = "打开蓝牙失败";
            }
            catch (Exception ex)
            {
                信息 = "打开蓝牙失败" + ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 关闭蓝牙4C83(int 通道, out string 信息, out string data, string 解密 = "01")
        {
            data = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息, 解密);
                if (!OK)
                {
                    return false;
                }
                bool result1 = false;
                string str = "05 2E 4C 83 02 00 00 00";
                for (int i = 0; i < 3; i++)//05 2E 4C 83 02 00 00 00
                {
                    result1 = zLGCANHelper.SentData(通道, 0x761, "05 2E 4C 83 02 00 00 00", true, SendType.正常发送);
                    eLog.AddLog($"关闭蓝牙4C83命令：{str}", eMsgType.Debug);
                    if (result1)
                    {
                        break;
                    }
                }
                if (!result1)
                {
                    信息 = "发送数据失败,关闭蓝牙失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);//03 6E 4C 83 AA AA AA AA 
                data = string.Join("\n", datas);
                eLog.AddLog($"关闭蓝牙4C83响应：{string.Join(",", datas)}", eMsgType.Debug);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {

                        if (s.Trim().StartsWith("03 6E 4C 83"))
                        {
                            信息 = "关闭蓝牙成功";
                            return true;
                        }
                    }
                }

                信息 = "关闭蓝牙失败";
            }
            catch (Exception ex)
            {
                信息 = "关闭蓝牙失败" + ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool MAC地址4C8B(int 通道, out string mac地址, out string 信息, out string data)
        {
            data = "";
            mac地址 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                //bool OK = Can.解密(通道, out 信息, "01");
                //if (!OK)
                //{
                //    信息 = "解密失败";
                //    mac地址 = 信息;
                //    return false;
                //}
                bool result1 = false;

                result1 = zLGCANHelper.SentData(通道, 0x761, "03 22 4C 8B 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(50);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(100);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(50);

                if (!result1)
                {
                    信息 = "发送数据失败,读取蓝牙 Mac地址失败";
                    mac地址 = 信息;
                    return false;
                }
                Thread.Sleep(500);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                //10 0A 62 4C 8B 00 48 42              
                // 21 21 77 24 80 AA AA AA
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);// 03 6E 4C 10 AA AA AA AA
                data = string.Join("\n", datas);
                string[] hexValues = new string[6];
                bool ok10 = false;
                bool ok21 = false;
                int num = 0;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i <= 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    else if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i < 1 || i > 4) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                mac地址 = string.Join("", hexValues);
                信息 = string.Join(",", hexValues);
                if (ok10 && ok21 && mac地址.Length == 12)
                {
                    return true;
                }
                else if (mac地址.Length != 12)
                {
                    信息 = "长度NG";
                    mac地址 = data;
                }
                else
                {
                    return false;
                }
                return false;
            }
            catch (Exception ex)
            {
                信息 = "读取蓝牙地址失败" + ex.Message;
                mac地址 = 信息;
                return false;
            }
        }
        [ExposedMethodAttribute("")]
        public bool 读连接蓝牙信号强度4C34(int 通道, out string 信息, out string data, out int 信号强度)
        {
            data = "";
            信号强度 = -99;
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    return false;
                }
                bool result1 = false;
                for (int i = 0; i < 3; i++)
                {
                    result1 = zLGCANHelper.SentData(通道, 0x761, "04 22 4C 34 00 00 00 00", true, SendType.正常发送);
                    if (result1)
                    {
                        break;
                    }
                }

                if (!result1)
                {
                    data = "发送数据失败,读连接蓝牙信号强度失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1000);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                data = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {

                        if (s.Trim().Contains("62 4C 34"))
                        {
                            信息 = "读连接蓝牙信号强度成功";
                            信号强度 = Convert.ToInt32(s.Split(' ')[6], 16) * -1; // 转换为十进制整数
                            if (s.Split(' ')[4] != "01")
                            {
                                信号强度 = -999;
                                return false;
                            }
                            return true;
                        }
                    }

                }
                //3、关闭
                信息 = "读连接蓝牙信号强度失败";
                return false;
            }
            catch (Exception ex)
            {
                信息 = "读连接蓝牙信号强度失败" + ex.Message;
                return false;
            }
        }
    }
}
